package com.fanyouzhao.eshop.core.pojo;

import com.fanyouzhao.eshop.core.groups.AddUserGroup;
import com.fanyouzhao.eshop.core.groups.UpdateUserGroup;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Date;

/**
 * @Author: fanyouzhao
 * @Date: 15:34 2021/4/23
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "tb_user")
@ApiModel("用户User")
public class User implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "user_id")
    @NotNull(message = "id不能为空",groups = UpdateUserGroup.class)
    @ApiModelProperty(value = "id",example = "18")
    private Integer id;

    @Column(name = "user_name")
    @NotEmpty(message = "用户名不能为空",groups = {AddUserGroup.class})
    @ApiModelProperty(value = "姓名",example = "张三丰")
    private String name;

    @Column(name = "user_phone")
    @Pattern(regexp = "^1[3|4|5|7|8][0-9]{9}$",message = "请输入正确手机号",groups = {AddUserGroup.class})
    @ApiModelProperty(value = "手机号",example = "15811110001")
    private String phone;

    @Column(name = "user_birth")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @ApiModelProperty(value = "出生日期yyyy-MM-dd")
    private Date birth;

    @Column(name = "user_sex")
    @ApiModelProperty(value = "性别",example = "男")
    private String sex;

    @Column(name = "user_regTime")
    @JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss")
    @ApiModelProperty("注册时间(不必传)")
    private Date regTime;

    public User(String name, String phone) {
        this.name = name;
        this.phone = phone;
    }

    public User(java.sql.Date regTime) {
        this.regTime = regTime;
    }
}